import { AudioSource, director,Node } from "cc";
import { ResManager } from "../res/resManager";


export class AudioManager{

    private static _instance:AudioManager = null!;
    
    // AudioSource 挂载在此节点上
    private m_AttachNode:Node = null;
    // AudioSource 组件
    private m_AudioSource:AudioSource = null;

    static getInstance(){
        if(this._instance === null){
            this._instance = new AudioManager;
        }

        return this._instance;
    }

    private constructor(){
        this.m_AttachNode = director.getScene().getChildByName("Canvas");
        this.m_AudioSource = this.m_AttachNode.addComponent(AudioSource)
    }


    playMusic(bUrl:{
        b:string,//子包名
        l:string    //资源路径
    }):void{
        ResManager.getInstance().loadAudioClip(bUrl.b,bUrl.l,audioClip =>{
            let audioSource = this.m_AudioSource;
            audioSource.clip = audioClip;
            audioSource.loop = true;
            audioSource.play();
        })
    }


}


